//
//  VcOfSecond.m
//  UI07_UINavigationController
//
//  Created by LGC on 16/3/17.
//  Copyright © 2016年 Apon. All rights reserved.
//

#import "VcOfSecond.h"
#import "VCOfThird.h"

@interface VcOfSecond ()
@property (nonatomic, retain)UIButton *button;

@end

@implementation VcOfSecond


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self configNaviBar];
    [self createButton];
    
    // 修改navigationController的栈数组.
    // 第一个界面对象.
    UIViewController *first = self.navigationController.viewControllers[0];
    
    // 第三个界面对象.
    VCOfThird *third = [[VCOfThird alloc]init];
    
    UIViewController *second = self.navigationController.topViewController;
    
    // 将第三个页面对象插入在栈中第一个页面和第二个页面中间, 使得第二个界面返回上一页到第三个界面.
    [self.navigationController setViewControllers:@[first,third, second] animated:YES];
    
    // Do any additional setup after loading the view.
}

#pragma mark - 创建一个Button用于返回上一界面
- (void)createButton {
    self.button = [UIButton buttonWithType:UIButtonTypeSystem];
    
    self.button.frame = CGRectMake(100, 100, 100, 100);
    
    [self.button setTitle:@"back" forState:UIControlStateNormal];
    
    [self.view addSubview:self.button];
    
    self.button.backgroundColor = [UIColor yellowColor];
    
    [self.button addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];

}
#pragma mark - 点击事件
- (void)backAction:(UIButton *)button {
    
    // 返回上一页
    [self.navigationController popViewControllerAnimated:YES];
    
}
#pragma mark - 配置Bar
/** 隐藏导航栏 */
- (void)configNaviBar {
    self.navigationController.navigationBarHidden = YES;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
